package com.cetool.autocms.controller.sys;

import com.cetool.autocms.annotation.TokenAnnotation;
import com.cetool.autocms.common.PageRequest;
import com.cetool.autocms.enumeration.OperateEnum;
import com.cetool.autocms.pojo.dto.sys.MenuInfoDTO;
import com.cetool.autocms.pojo.dto.sys.TopMenuListDTO;
import com.cetool.autocms.pojo.request.sys.BatchDeleteMenuRequest;
import com.cetool.autocms.pojo.request.sys.QueryMenuListRequest;
import com.cetool.autocms.pojo.request.sys.SaveMenuRequest;
import com.cetool.autocms.service.sys.MenuService;
import com.github.pagehelper.PageSerializable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 菜单管理控制层
 *
 * @author 戴越
 * @date 2021/11/24
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "系统管理-菜单管理")
public class MenuController {
    /**
     * 注入菜单管理服务
     */
    @Autowired
    private MenuService menuService;

    /**
     * 分页查询菜单信息列表
     *
     * @param request 分页查询菜单列表请求实体
     * @return 菜单信息分页列表
     * @author 戴越
     * @date 2021/11/24
     */
    @TokenAnnotation
    @PostMapping("/listPageMenuInfo")
    @ApiOperation(value = "分页查询菜单信息列表")
    public PageSerializable<MenuInfoDTO> listPageMenuInfo(@RequestBody PageRequest<QueryMenuListRequest> request) {
        return menuService.listPageMenuInfo(request);
    }

    /**
     * 新增菜单
     *
     * @param request 新增菜单请求实体
     * @return 操作信息
     * @author 戴越
     * @date 2021/11/24
     */
    @TokenAnnotation
    @PostMapping("/saveMenu")
    @ApiOperation(value = "新增菜单")
    public OperateEnum saveMenu(@Valid @RequestBody SaveMenuRequest request) {
        return menuService.saveMenu(request);
    }

    /**
     * 一级菜单下拉列表
     *
     * @return 一级菜单信息传输实体
     * @author 戴越
     * @date 2021/11/24
     */
    @TokenAnnotation
    @PostMapping("/queryTopMenuList")
    @ApiOperation(value = "一级菜单下拉列表")
    public List<TopMenuListDTO> queryTopMenuList() {
        return menuService.queryTopMenuList();
    }

    /**
     * 批量删除菜单
     *
     * @param request 批量删除菜单参数请求实体
     * @return 操作信息
     * @author 戴越
     * @date 2021/11/25
     */
    @TokenAnnotation
    @PostMapping("/batchDeleteMenu")
    @ApiOperation(value = "批量删除菜单")
    public OperateEnum batchDeleteMenu(@Valid @RequestBody BatchDeleteMenuRequest request) {
        return menuService.batchDeleteMenu(request);
    }

}
